﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace PrattParsing
{
    [DebuggerNonUserCode]
    public class Token
    {
        public const int EOF_TYPE = -1;

        public static Dictionary<int, string> TYPE_NAMES;

        static Token()
        {
            TYPE_NAMES = new Dictionary<int, string>();
            TYPE_NAMES[-1] = "EOF";
        }

        public int type { get; set; }
        public string text { get; set; }
        public TextPos pos { get; set; }
        public object data { get; set; }

        public Token(int type, string text, TextPos pos, object data)
        {
            this.type = type;
            this.text = text;
            this.pos = pos;
            this.data = data;
        }
        public Token(int type, string text, TextPos pos)
        {
            this.type = type;
            this.text = text;
            this.pos = pos;
            this.data = null;
        }
        public Token(int type, TextPos pos, object data)
        {
            this.type = type;
            this.pos = pos;
            this.data = data;
            this.text = data.ToString();
        }

        public T getData<T>()
        {
            return (T)data;
        }

        public override string ToString()
        {
            return TYPE_NAMES[type] + " \"" + text + "\"";
        }
        
        public static Token EOF(TextPos pos)
        {
                return new Token(EOF_TYPE, "EOF", pos, true);
        }
    }
}
